<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8"/>
    <title>酒店登录页面</title>
    <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
    <link rel="stylesheet" type="text/css" href="css/hotel.css"/>
    <script type="text/javascript" src="layer/layer.js"></script>
</head>
<body class="login-body">
<input type="hidden" id="UserStatusid" th:value="${session.UserStatusid}"/>
<script type="text/javascript">
    var ustatusid = $('#UserStatusid').val();
    if(ustatusid == 1){
        window.location.href = "toDecode.do";
    }
</script>
<form action="" method="post">
    <div class="login">
        <div class="login-text">
            <ul>
                <li><label for="userAccount">账号:</label></li>
                <li><label for="userPassword">密码:</label></li>
                <li>类型:</li>
            </ul>
        </div>
        <div class="login-input">
            <ul>
                <li><input type="text" name="" id="userAccount" placeholder="请输入用户"/></li>
                <li><input type="password" name="" id="userPassword" placeholder="请输入密码"/></li>
                <li>
                    <select id="selectType">
                        <option value="管理员">管理员</option>
                        <option value="经理">经理</option>
                    </select>
                </li>
            </ul>
        </div>
        <div class="login-a">
            <ul>
                <li><a href="toRegist.do">注册新账号</a></li>
                <li><a href="toRetrieve.do">找回密码</a></li>
            </ul>
        </div>
    </div>
    <div class="btnlogin">
        <button class="btn-login" id="btn-login" type="button">登录</button>
    </div>
</form>
<script type="text/javascript">
    $('#userAccount').blur(checkUser);
    $('#userPassword').blur(checkPassword);
    var userAccount;
    var userPassword;
    function checkUser() {
        userAccount = $('#userAccount').val();
        var reg_userAccount = /^\w{6,10}$/;
        var flag = reg_userAccount.test(userAccount);
        if (flag) {
            $("#userAccount").css("border", "");
        } else {
            layer.tips('账号需满足6到10位', '#userAccount');
            $("#userAccount").css("border", "1px solid red");
        }
        return flag;
    }
    function checkPassword() {
        userPassword = $('#userPassword').val();
        var reg_userPassword = /^\w{6,10}$/;
        var flag = reg_userPassword.test(userPassword);
        if (flag) {
            $("#userPassword").css("border", "");
        } else {
            layer.tips('密码需满足6到10位', '#userPassword');
            $("#userPassword").css("border", "1px solid red");
        }
        return flag;
    }
    var selectType;
    selectType = $('#selectType').val();
    $(function () {
        $('#selectType').change(function (){
            selectType = $('#selectType').val();
        });
    });
    $('#btn-login').click(function (){
        if(checkUser()&&checkPassword()){
            $.post(
                "login.do",
                {"userAccount":userAccount,"userPassword":userPassword,"selectType":selectType},
                function (data){
                    if (data.status == 0) {
                        window.location.href = "toIndex.do";
                    } else if (data.status == 1) {
                        layer.msg(data.message);
                    }
                }
            );
        }else {
            layer.msg('请检查信息是否正确');
        }
    })
</script>
</body>
</html>
